//#include <iostream>
//#include <unistd.h>
//#include <sys/types.h>
//using namespace std;
//
//int main()
//{
//    while(1)
//    {
//        cout << getpid() << endl;
//        sleep(2);
//    }
//    return 0;
//}

#include <iostream>
#include <unistd.h>
#include <sys/types.h>
using namespace std;
int main()
{
    cout << "子进程" << getpid() << "父进程" << getppid() << endl;
    pid_t id = fork();

    if(id == 0)
    {
        while(1)
        {
            cout << "子进程" << getpid() << "父进程" << getppid() << endl;
            sleep(2);
        }
    }

    else if(id > 0)
    {
        while(1)
        {
            cout << "子进程" << getpid() << "父进程" << getppid() << endl;
            sleep(2);
        }
    }

    else cerr << "错误" << endl;
    return 0;
}
